package edu.purdue.cs.aggr.messageprocessor;

import edu.purdue.cs.aggr.AggrException;
import edu.purdue.cs.aggr.VertexManager;
import edu.purdue.cs.aggr.message.Message;
import edu.purdue.cs.aggr.message.VertexMoveCommand;
import edu.purdue.cs.aggr.message.VertexTransferMessage;

public class VertexMoveCommandProcessor extends MessageProcessor
{
  private VertexManager manager;

  public VertexMoveCommandProcessor(VertexManager manager)
  {
    this.manager = manager;
  }

  @Override
  public void processMessage(Message message) throws AggrException
  {
    VertexMoveCommand moveMessage = (VertexMoveCommand) message;

    // store vertex we want to move into the transfer message
    VertexTransferMessage transferMessage = new VertexTransferMessage();
    transferMessage.setDestination(moveMessage.getTargetId());
    transferMessage.setVertex(manager.getVertex(moveMessage.getVertexId()));
    
    System.out.println("Moving vertex to " + moveMessage.getTargetId());
    
    // send the message
    manager.getSender().sendMessage(transferMessage, moveMessage.getTargetId());
  }
}
